<?php
session_start();
ob_start();
	/*Getting the Current page used for the actual class in the menu*/
	$currentPage = $_SERVER['SCRIPT_NAME'];
	$currentPage = explode("/", $currentPage);
	$currentPage = $currentPage[count($currentPage) - 1];

	if(isset($_SESSION['username'])){
		$sUsername = $_SESSION['username'];

		/*Getting the coins*/
		require("sql/connection.php");
		require_once("utilities/functions.php");
		$playerid = getPlayerId($dbc,$sUsername);

		$query = "SELECT coins FROM Players where nickname = '$sUsername'";
		
		$r = mysqli_query($dbc,$query);
		$data = mysqli_fetch_array($r,MYSQLI_ASSOC);

		//Getting pending notifications
		$query = "SELECT COUNT(notification_id) AS npending FROM Notifications WHERE player_id = '$playerid' AND seen = 0";
		$r = mysqli_query($dbc,$query);
		$datan = mysqli_fetch_array($r,MYSQLI_ASSOC);
	}
	?>

<!doctype html>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<title><?php echo $page_title; ?></title>
	<script src="assets/js/jquery-1.10.2.js"></script>
	<script type="text/javascript" src="assets/js/bootstrap.js"></script>
	<link rel="stylesheet" href="assets/css/bootstrap.css">
	<link rel="shortcut icon" href="images/favicon.ico" />
</head>
<body>

<!-- header -->
	<nav class="navbar navbar-default" role="navigation">
		<div class="container">
			<a href="#" class="navbar-brand">21 Game</a>
			<ul class="nav navbar-nav">
				<li <?php if($currentPage == "index.php") echo "class ='active'"; ?>><a href="index.php">Index</a></li>
				<li <?php if($currentPage == "register.php") echo "class ='active'"; ?>><a href="register.php">Register</a></li>
				<?php 
					if(!isset($_SESSION['username'])){
						?>
				<li <?php if($currentPage == "login.php") echo "class ='active'"; ?>><a href="login.php">Login</a></li>
						<?php		
					}
					else{
					?>
				<li <?php if($currentPage == "challenge.php") echo "class ='active'"; ?>><a href="challenge.php">Challenge player</a></li>
				<li <?php if($currentPage == "logout.php") echo "class ='active'"; ?>><a href="logout.php">Logout</a></li>
				<li class="dropdown <?php if($currentPage == 'yourgames.php') echo 'active'; ?>"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="glyphicon glyphicon-user"></i><b class="caret"></b></a>
							<ul class="dropdown-menu">
								<li><a href="yourgames.php">Your Games</a></li>
							</ul>
						</li>
				<li <?php if($currentPage == "notifications.php") echo "class ='active'"; ?>><a href="notifications.php"><i class="glyphicon glyphicon-envelope"></i>&nbsp<span class="badge pull-right"><?php if($datan['npending'] != 0) echo $datan['npending']; ?></span></a></li>
						<?php	
					}
				 ?>
			</ul>
			<?php 
				if(isset($_SESSION['username'])){
					?><p class="navbar-text navbar-right">Coins: <b><?php echo $data['coins']; ?></b>&nbsp&nbsp&nbspSigned in as <a href="#" class="navbar-link"><?php echo "{$_SESSION['username']}"; ?></a></p><?php
				}
				else{
					?><p class="navbar-text navbar-right">You are not logged in</p><?php
				}
			 ?>
		</div>
	</nav>
	<!-- end header -->